package com.king.java.tools.excel.easy;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelReader;
import com.alibaba.excel.read.metadata.ReadSheet;
import com.king.java.tools.excel.CaseRead;
import com.king.java.tools.excel.CaseResult;
import com.king.java.tools.excel.easy.listener.CaseDataLinstener;
import com.king.java.tools.excel.entity.CaseData;

/**
 * 描述: EasyExcelRead 读取excel内容
 *
 * @author : sujinchen
 * @date : 2020/11/3
 */
public class EasyExcelRead implements CaseRead {
    @Override
    public CaseResult read(String path,int sheetIndex) {
        ReadSheet sheet = EasyExcel.readSheet(sheetIndex).build();
        return read(path, sheet);
    }

    @Override
    public CaseResult read(String path, String sheetName) {

        ExcelReader build = null;
        CaseDataLinstener caseDataLinstener = new CaseDataLinstener();
        try {
            build = EasyExcel.read(path, CaseData.class, caseDataLinstener).build();
            ReadSheet sheet = EasyExcel.readSheet(sheetName).build();

            build.read(sheet);
        }finally {
            if (build != null) {
                build.finish();
            }
            return caseDataLinstener;
        }
    }



    private CaseResult read(String path,ReadSheet readSheet) {
        return null;
    }
}
